package BookMethods;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DeleteMethod implements BookMethods{

    @Override
    public void method(BookList booklist) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("输入要删除的书的名字");
        String bookName = scanner.nextLine();


        int pos = -1;

        for (int i = 0; i < booklist.getUsedSize(); i++) {
            Book book = booklist.getBook()[i];
            if (bookName.equals(book.getBookName())) {
                pos = i;
                break;
            }
        }

        if (pos == -1) {
            System.out.println("未找到该书");
            return;
        }

        for (int j = pos; j < booklist.getUsedSize() - 1; j++) {
            Book book = booklist.getBook()[j + 1];
            booklist.setBook(j, book);
        }

        booklist.setUsedSize(booklist.getUsedSize() - 1);
        System.out.println("删除成功");
    }
}
